package com.own.component.sms.core.model;

import com.own.component.common.util.FormUtil;
import com.own.component.sms.core.base.BaseSmsType;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;

import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

/**
 * SmsSendModel
 *
 * @author chenxueli
 * @date 2023-06-26 11:55:09
 */
@Getter
public class SmsSendModel {

    @Schema(title = "使用的方式")
    private final BaseSmsType type;

    @Schema(title = "手机号列表")
    private final Set<String> phoneList;

    @Schema(title = "模板id/code")
    private final String templateId;
    @Schema(title = "参数信息")
    private final Map<String, String> paramMap;
    @Schema(title = "签名名称")
    @Setter
    private String signName;

    public SmsSendModel(String templateId) {
        this.type = null;
        this.templateId = templateId;
        this.phoneList = new HashSet<>();
        this.paramMap = new HashMap<>();
    }

    public SmsSendModel(String templateId, BaseSmsType type) {
        this.type = type;
        this.templateId = templateId;
        this.phoneList = new HashSet<>();
        this.paramMap = new HashMap<>();
    }

    /**
     * 添加手机号信息
     *
     * @param phone 手机号
     * @return this
     */
    public SmsSendModel add(String phone) {
        if (FormUtil.isPhone(phone)) {
            phoneList.add(phone);
        }
        return this;
    }

    /**
     * 添加手机号信息
     *
     * @param phoneList 手机号
     * @return this
     */
    public SmsSendModel add(Collection<String> phoneList) {
        phoneList.forEach(this::add);
        return this;
    }

    /**
     * 添加参数信息
     *
     * @param key   参数key
     * @param value 参数value
     * @return this
     */
    public SmsSendModel put(String key, String value) {
        paramMap.put(key, value);
        return this;
    }

}
